﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Yanzhengma
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        public static string CreateRandomCode(int length)  //生成由数字和大小写字母组成的验证码
        {
            string list = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
            //list中存放着验证码的元素
            Random random = new Random();
            string code = "";   //验证码
            for (int i = 0; i < length; i++)   //循环6次得到一个伪随机的六位数验证码
            {
                code += list[random.Next(0, list.Length - 1)];
            }
            return code;

        }
            private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = CreateRandomCode(4);   //生成一个4位的验证码,并显示在标签lable上。
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = CreateRandomCode(4);   //生成一个4位的验证码,并显示在标签lable上。
        }

        private void button2_Click(object sender, EventArgs e)
        {

            if (textBox1.Text.ToLower() != label1.Text.ToLower())   //验证码输入错误
            {
                MessageBox.Show("您输入的验证码有误！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                CheckCode_Click(sender, e);   //刷新一遍验证码
                textBox1.Text = "";    //清空验证码输入框
            }
            else   //验证成功
            {
                MessageBox.Show("验证成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void CheckCode_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
